package com.usian.lister;


import com.usian.utils.common.AliCodeUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RabbitMQLister {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "one")
    public void sendCode(String phone){
        AliCodeUtils aliCodeUtils = new AliCodeUtils();
        try {
            aliCodeUtils.sendCode(phone,"199955");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        stringRedisTemplate.opsForValue().set(phone,"199955");
        stringRedisTemplate.expire(phone,60, TimeUnit.MINUTES);
    }
}